import util from '@/network/common/util_hq.js';
import $ from 'jquery'

let postCfg = {
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    transformRequest: function (data) {
        return $.param(data)
    }
}
let api = {
    'getCard'           : '/management/v1/getCard', //会员卡查询会员卡信息
    'getCardList'       : '/management/v1/getCardList', //手机号查询会员卡
    'getCardIdBean'     : '/management/v1/getCardIdBean', //根据id查询会员卡
    'getCardBean'       : '/management/v1/getCardBean', //会员卡详情
    'cardPassword'      : '/management/v1/cardPassword', //修改密码
    'updateCardNo'      : '/management/v1/updateCardNo', //换卡
    'updateCardStatus'  : '/management/v1/updateCardStatus', //挂失
    'updateCardPhone'   : '/management/v1/updateCardPhone', //修改手机号
    'addCard'           : '/management/v1/addCard', //发卡
    'addCardType'       : '/management/v1/addCardType', //发卡
    'addCardOrder'      : '/management/v1/addCardOrder', //充值
    
}
let res = {};
function getCard (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getCard, {
            cardNo: params.cardNo,
            tid: params.tid
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getCardList (phoneNum) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getCardList, {
            phoneNum: phoneNum,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getCardIdBean (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getCardIdBean, {
            cid: params.cid,
            cardNo: params.cardNo
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function getCardBean (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.getCardBean, {
            cid: params.cid,
            type: params.type,
            page: params.page,
            pageSize: params.pageSize,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}

function cardPassword (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.cardPassword, {
            cid: params.cid,
            password: params.password,
            newPassword: params.newPassword,
            submitPassword: params.submitPassword
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function updateCardNo (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.updateCardNo, {
            cid: params.cid,
            cardCategoryId: params.cardCategoryId,
            cardNo: params.cardNo,
            password: params.password
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function updateCardStatus (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.updateCardStatus, {
            cid: params.cid,
            password: params.password
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function updateCardPhone (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.updateCardPhone, {
            cid: params.cid,
            phone: params.phone,
            type: '1',
            vcode: params.vcode,
            password: params.password
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function addCard (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.addCard, {
            tid: params.tid,
            cid: params.cid,
            cardNo: params.cardNo,
            stopCardNo: params.stopCardNo,
            managementType: params.managementType,
            status: params.status,
            theaterName: params.theaterName,
            phone: params.phone,
            userId: params.userId,
            userName: params.userName,
            idNo: params.idNo,
            addr: params.addr,
            gender: params.gender,
            password: params.password,
            confirmThePassword: params.confirmThePassword,
            money: params.money,
            type: params.type,
            teamName: params.teamName,
            creatorId: params.creatorId,
            setPhoneLogin: params.setPhoneLogin
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
function addCardOrder (params) {
    let p = new Promise(function (resolve, reject) {
        util.ajax.post(api.addCardOrder, {
            did: params.did,
            cid: params.cid,
            cardNo: params.cardNo,
            money: params.money,
        }, postCfg).then(function(res) {
            resolve(res);
        }, function(error) {
            reject(error);
        });
    });
    return p;
}
export default {
    getCard,
    getCardList,
    getCardIdBean,
    getCardBean,
    cardPassword,
    updateCardNo,
    updateCardStatus,
    updateCardPhone,
    addCard,
    addCardOrder
}